package com.baidu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baidu.mapper.MemberMapper;
import com.baidu.mapper.OrderMapper;
import com.baidu.mapper.SetMealMapper;
import com.baidu.service.ReportService;
import com.baidu.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass = ReportService.class)
@Transactional //应为是业务层需要加一个事务。

public class ReportServiceImpl implements ReportService {

	@Autowired
	private MemberMapper memberMapper;
	@Autowired
	private OrderMapper orderMapper;
	@Autowired
	private SetMealMapper setMealMapper;



/*
 data:{
reportData:{
    reportDate:null,
    todayNewMember :0,
    totalMember :0,
    thisWeekNewMember :0,
    thisMonthNewMember :0,
    todayOrderNumber :0,
    todayVisitsNumber :0,
    thisWeekOrderNumber :0,
    thisWeekVisitsNumber :0,
    thisMonthOrderNumber :0,
    thisMonthVisitsNumber :0,
    hotSetmeal :[
        {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222},
        {name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}
    ]
}
 */


	@Override
	public Map<String, Object> getBusinessReportData() throws Exception {

		HashMap<String, Object> map = new HashMap<>();

		Date today1 = DateUtils.getToday();
//		今天
		String today = DateUtils.parseDate2String(DateUtils.getToday());

//		本周一
		String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday(today1));

//		本月一号
		String thisMonthFirstDay = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
// -------------------------sql

// todayNewMember
		int todayNewMember=	memberMapper.findNewMemberByToday(today);
//totalMember
		int totalMember=	memberMapper.findtotalMember();
// thisWeekNewMember
		int thisWeekNewMember=	memberMapper.findthisWeekNewMemberBythisWeekMonday(thisWeekMonday);
//thisMonthNewMember
		int thisMonthNewMember=	memberMapper.findthisMonthNewMember(thisMonthFirstDay);
//todayOrderNumber
	int todayOrderNumber=	orderMapper.findtodayOrderNumber(today);

//todayVisitsNumber
		int todayVisitsNumber=	orderMapper.todayVisitsNumber(today);

//thisWeekOrderNumber
		int thisWeekOrderNumber=	orderMapper.thisWeekOrderNumber(thisWeekMonday);
//thisWeekVisitsNumber
		int thisWeekVisitsNumber=	orderMapper.thisWeekVisitsNumber(thisWeekMonday);
//thisMonthOrderNumber
		int thisMonthOrderNumber=	orderMapper.thisMonthOrderNumber(thisMonthFirstDay);
//thisMonthVisitsNumber
		int thisMonthVisitsNumber=	orderMapper.thisMonthVisitsNumber(thisMonthFirstDay);

//hotSetmeal
		ArrayList<Map<String, Object>> hotSetmeal =setMealMapper.findhotSetmealBythisMonthFristDay();


		map.put("reportDate",today);
		map.put("todayNewMember",todayNewMember);
		map.put("totalMember",totalMember);
		map.put("thisWeekNewMember",thisWeekNewMember);
		map.put("thisMonthNewMember",thisMonthNewMember);
		map.put("todayOrderNumber",todayOrderNumber);
		map.put("todayVisitsNumber",todayVisitsNumber);
		map.put("thisWeekOrderNumber",thisWeekOrderNumber);
		map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
		map.put("thisMonthOrderNumber",thisMonthOrderNumber);
		map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
		map.put("hotSetmeal",hotSetmeal);



		return map;
	}



}
